//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------
/*
*/

package uxgenes.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;


//
// UXGEN Activity
//

public class UXActivity	extends Activity implements uxgenes.core.EngineContext.ActivityInterface
{
// variables //
	protected uxgenes.core.EngineContext	engine;
		
	
// Activity //

	// onCreate
	@Override
	protected void onCreate (Bundle savedInstanceState)
	{
		super.onCreate( savedInstanceState );
		setVolumeControlStream( AudioManager.STREAM_MUSIC );
		engine = new uxgenes.core.EngineContext( this, this );
	}
	
	
	// onDestroy
	@Override
	protected void onDestroy ()
	{
		super.onDestroy();
		engine.OnDestroy();
		engine = null;
	}

	
	// onPause
	@Override
	protected void onPause ()
	{
		super.onPause();
		engine.OnPause();
	}

	
	// onResume
	@Override
	protected void onResume ()
	{
		super.onResume();
		engine.OnResume();
	}
	
	
	// onStart
	@Override
	protected void onStart ()
	{
		super.onStart();
		engine.OnStart();
	}

	
	// onStop
	@Override
	protected void onStop ()
	{
		super.onStop();
		engine.OnStop();
	}

	
	// onLowMemory
    @Override
    public void onLowMemory ()
    {
        super.onLowMemory();
        engine.OnLowMemory();
    }
    
    
    // onWindowFocusChanged
    @Override
    public void onWindowFocusChanged (boolean hasFocus)
    {
    	engine.OnWindowFocusChanged( hasFocus );
    }

    
    
// Utils //
	
    // SetWakeLock
	public final void SetWakeLock (boolean enabled)
	{
		if ( enabled ) {
			getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
		}
		else {
			getWindow().clearFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
		}
	}
	
	
	// Inflate
	public final View Inflate (int layoutId)
	{
		LayoutInflater	inflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		return inflater.inflate( layoutId, null );
	}
	
	
	// onConfigurationChanged
	@Override
	public void onConfigurationChanged (Configuration newConfig)
	{
		super.onConfigurationChanged(newConfig);

		engine.UpdateDisplayOrientation();
	}
    
	
// EngineContext.ActivityInterface //
    
    // Close
	public final void Close ()
	{
		finish();
	}

	
	// SetRequestedOrientation
	public final void SetRequestedOrientation (int orient)
	{
		this.setRequestedOrientation( orient );
	}
}
